package com.nowcoder.community.dao.elasticsearch;

import com.nowcoder.community.entity.DiscussPost;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.annotations.Highlight;
import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.HighlightParameters;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository                                                         //<处理的对象，对象的主键类型>
public interface DiscussPostRepository extends ElasticsearchRepository<DiscussPost,Integer> {

    @Highlight(
            fields = {
                    @HighlightField(name = "title"),
                    @HighlightField(name = "content")
            },parameters = @HighlightParameters(
                    preTags = "<em>",
                    postTags = "</em>",
                    numberOfFragments = 0
    ))
    //@Query("{\"bool\":{\"must\":[{\"query_string\":{\"query\":\"?*\",\"fields\":[\"title\"]},\"analyze_wildcard\":true},{\"query_string\":{\"query\":\"?*\",\"fields\":[\"content\"]},\"analyze_wildcard\":true}]}}")
    List<SearchHit<DiscussPost>> findDiscussPostByTitleLikeOrContentLike(String title,String content,Pageable pageable);//, Sort sort

    Page<DiscussPost> findDiscussPostByUserId(int userId,Pageable pageable);
}
